﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

using System;
using Majesty_of_Omega.Config;

namespace Majesty_of_Omega.Model.Report
{
    /// <summary>
    /// Entry in a situation report
    /// </summary>
    [Serializable]
    public class SitReportEntry
    {
        /// <summary>
        /// Priority of this entry 
        /// </summary>
        private SitReportPriority reportPriority = SitReportPriority.Green;

        /// <summary>
        /// The underlying event of the situation report
        /// </summary>
        private readonly SitReportType sitReportType;

        /// <summary>
        /// Initializes a new empty instance of the <see cref="SitReportEntry"/> class.
        /// </summary>
        /// <remarks>
        /// This constructor exists for serializing purposes
        /// </remarks>
        public SitReportEntry()
        {
            
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SitReportEntry"/> class out
        /// of an event from the SitReportTable.xml data file.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="targetHyperlinkObject">
        /// A SitReportEntry will be displayed with a hyperlink. The User could click on the hyperlink
        /// and navigate to the target. The type of the targetHyperlinkObject depends 
        /// on the <see cref="SitReportType"/>. When you have a <see cref="SitReportType.ResearchUnlockTechField"/> entry,
        /// the targetHyperlinkObject is the discovered Technology Field.
        /// The combination of <see cref="sitReportType"/> and targetHyperlinkObject will be combined to 
        /// logical link. In the UI this link will be evaluated and the corresponding xaml page will be shown.
        /// </param>
        /// <param name="args">The args.</param>
        public SitReportEntry(SitReportType type, object targetHyperlinkObject, params object[] args)
        {
            sitReportType = type;
            SitReportEvent reportEvent = SpreadSheetManager.SitReportTable.GetReportEvent(type);
            Description = StringManager.GetStringFormatted(reportEvent.Description_ID, args);
            reportPriority = reportEvent.Priority;
            Icon = reportEvent.Icon;
            TargetHyperlinkObject = targetHyperlinkObject;
        }

        /// <summary>
        /// Gets the link.
        /// </summary>
        /// <value>The link.</value>
        public string Link
        {
            get
            {
                return sitReportType.ToString();   
            }
        }

        /// <summary>
        /// Gets the target object for building a unique hyperlink to more information
        /// </summary>
        /// <remarks>
        /// For more information look at the constructor summary of the <see cref="SitReportEntry"/> class
        /// </remarks>
        /// <value>The target object.</value>
        public object TargetHyperlinkObject { get; private set; }

        /// <summary>
        /// Gets the type of the sit report entry. This type maps to the exact event.
        /// </summary>
        /// <remarks>
        /// Look at the SitReportTable.xml file for more information
        /// </remarks>
        /// <value>The type of the sit report.</value>
        public SitReportType ReportType
        {
            get { return sitReportType; }
        }

        /// <summary>
        /// Gets or sets the severity.
        /// </summary>
        /// <value>The severity.</value>
        public SitReportPriority ReportPriority
        {
            get { return reportPriority; }
            set { reportPriority = value; }
        }

        /// <summary>
        /// Gets or sets the text of the event.
        /// </summary>
        /// <value>The description of the event</value>
        public string Description { get; set; }

        /// <summary>
        /// Gets or sets the icon.
        /// </summary>
        /// <value>The icon.</value>
        public string Icon { get; set; }

        /// <summary>
        /// Equalses the specified obj.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        public bool Equals(SitReportEntry obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            return Equals(obj.Description, Description) && Equals(obj.sitReportType, sitReportType) && Equals(obj.reportPriority, reportPriority);
        }

        /// <summary>
        ///                     Determines whether the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />.
        /// </summary>
        /// <returns>
        /// true if the specified <see cref="T:System.Object" /> is equal to the current <see cref="T:System.Object" />; otherwise, false.
        /// </returns>
        /// <param name="obj">
        ///                     The <see cref="T:System.Object" /> to compare with the current <see cref="T:System.Object" />. 
        ///                 </param>
        /// <exception cref="T:System.NullReferenceException">
        ///                     The <paramref name="obj" /> parameter is null.
        ///                 </exception><filterpriority>2</filterpriority>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (SitReportEntry)) return false;
            return Equals((SitReportEntry) obj);
        }

        /// <summary>
        ///                     Serves as a hash function for a particular type. 
        /// </summary>
        /// <returns>
        ///                     A hash code for the current <see cref="T:System.Object" />.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override int GetHashCode()
        {
            unchecked
            {
                int result = (Description != null ? Description.GetHashCode() : 0);
                result = (result*397) ^ sitReportType.GetHashCode();
                result = (result*397) ^ reportPriority.GetHashCode();
                return result;
            }
        }

        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(SitReportEntry left, SitReportEntry right)
        {
            return Equals(left, right);
        }

        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(SitReportEntry left, SitReportEntry right)
        {
            return !Equals(left, right);
        }
    }
}